package homework;

public class Cj implements Runnable {
    int[] arr = {10, 5, 20, 50, 100, 200, 500, 800, 2, 80, 300, 700};
    int num = arr.length;
    boolean[] flag = new boolean[arr.length];
    public void run() {
        while (true) {
            synchronized (this) {
                if (num > 0) {
                    int index = (int) (Math.random() * arr.length);
                    int get = arr[index];
                    // 代表这张抽奖券抽过了
                    if (flag[index] != true) {
                        flag[index] = true;
                        System.out.println(Thread.currentThread().getName()
                                + " 又产生了一个" + get + "元大奖");
                        num--;
                    }
                }
            }
        }
    }
}